using voidbox;
using System.ComponentModel;
using TTEngine.Graphics;
using TTEngine.TTMath;
using voidbox;

namespace TTEngine.Resource
{
    //初始化一些常用资源
    public class CommonResource
    {
        public TTEngine.Resource.ResourcePackage Package
        {
            get;
            private set;
        }


        #region logo 原文
        public static readonly byte[] logo_png_bytes_cs = new byte[]{
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x08,0x03,0x00,0x00,0x00,0x44,0xa4,0x8a,
0xc6,0x00,0x00,0x00,0x19,0x74,0x45,0x58,0x74,0x53,0x6f,0x66,0x74,0x77,0x61,0x72,
0x65,0x00,0x41,0x64,0x6f,0x62,0x65,0x20,0x49,0x6d,0x61,0x67,0x65,0x52,0x65,0x61,
0x64,0x79,0x71,0xc9,0x65,0x3c,0x00,0x00,0x00,0x1b,0x50,0x4c,0x54,0x45,0xdb,0xdb,
0xdb,0xdf,0x71,0x26,0xa5,0x69,0x3d,0x48,0x3e,0x0d,0x6c,0x3f,0x1e,0xe6,0xc7,0x24,
0x00,0x00,0x00,0xe2,0x8b,0x4b,0xff,0xff,0xff,0xf6,0x80,0x67,0x2a,0x00,0x00,0x00,
0x09,0x74,0x52,0x4e,0x53,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x53,0x4f,
0x78,0x12,0x00,0x00,0x00,0xd6,0x49,0x44,0x41,0x54,0x78,0xda,0xac,0xd3,0x0b,0x0e,
0xc3,0x20,0x08,0x00,0x50,0x05,0xd4,0xde,0xff,0xc4,0xe3,0x5b,0x95,0xda,0x2c,0x59,
0x46,0xb2,0xd6,0x94,0x17,0x45,0x74,0xe5,0xb2,0x20,0xca,0x03,0x8f,0xe2,0x9f,0xc7,
0xa0,0x7d,0xb0,0x03,0xfe,0x6c,0x09,0x1a,0x47,0xa0,0x79,0xce,0x48,0x64,0xc1,0x00,
0xd1,0x41,0x04,0xe1,0x06,0xb0,0x35,0x02,0xcb,0x00,0xc0,0x43,0x94,0x25,0x3f,0xa7,
0x68,0xf8,0x1b,0xe8,0xc5,0x1f,0x19,0x54,0x17,0xbd,0xfb,0x23,0x83,0xf6,0x15,0xc8,
0x14,0xb1,0x03,0xd9,0xcb,0x03,0xdc,0x8b,0x78,0x8d,0xf5,0x01,0x58,0x4c,0x42,0xf5,
0x08,0x80,0x22,0xb8,0xe5,0x47,0xf0,0xd2,0xec,0x33,0x58,0xc4,0x0a,0xfc,0x30,0x79,
0xf0,0x02,0x2c,0xa7,0xbf,0x59,0x45,0xe9,0xd8,0x2a,0x97,0x4d,0xde,0x07,0xbb,0x3a,
0x34,0x45,0xb9,0x4c,0xd4,0xd8,0x42,0x3e,0x30,0xbe,0x30,0x1d,0xab,0x92,0xbc,0x13,
0x13,0x72,0xe5,0xba,0xd5,0xb1,0x6c,0x45,0x2b,0x69,0x2a,0xf4,0x4e,0xae,0x02,0x96,
0x29,0x44,0xd8,0xad,0xde,0x84,0x11,0x10,0xc0,0xc2,0xff,0x17,0xdb,0x2a,0x7c,0x9c,
0xba,0x98,0x0a,0x07,0xa9,0x0e,0xaa,0x21,0x6e,0x10,0x22,0x32,0xd6,0xda,0x7f,0x03,
0x0f,0xe9,0xa7,0xbf,0xe5,0x35,0xc1,0x4b,0x7c,0x04,0x18,0x00,0x91,0x3e,0x17,0xc7,
0x8b,0x41,0xec,0x0c,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
        #endregion
        #region ascII12 原文
        public static readonly byte[] ASCII12_bin_bytes_cs = new byte[]{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,
0x10,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x6c,0x48,0x48,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x14,0x14,0x28,0x7c,0x28,0x7c,0x28,0x50,0x50,0x00,0x00,
0x00,0x10,0x38,0x40,0x40,0x38,0x48,0x70,0x10,0x10,0x00,0x00,0x00,0x20,0x50,0x20,
0x0c,0x70,0x08,0x14,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x20,0x20,0x54,0x48,
0x34,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x00,0x00,0x20,0x20,0x10,
0x10,0x10,0x10,0x10,0x10,0x20,0x20,0x00,0x00,0x10,0x7c,0x10,0x28,0x28,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0xfc,0x10,0x10,0x10,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x10,0x30,0x20,0x00,0x00,0x00,0x00,0x00,
0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,
0x30,0x00,0x00,0x00,0x00,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x00,0x00,
0x00,0x38,0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x30,0x10,0x10,
0x10,0x10,0x10,0x10,0x7c,0x00,0x00,0x00,0x00,0x38,0x44,0x04,0x08,0x10,0x20,0x44,
0x7c,0x00,0x00,0x00,0x00,0x38,0x44,0x04,0x18,0x04,0x04,0x44,0x38,0x00,0x00,0x00,
0x00,0x0c,0x14,0x14,0x24,0x44,0x7c,0x04,0x0c,0x00,0x00,0x00,0x00,0x3c,0x20,0x20,
0x38,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x1c,0x20,0x40,0x78,0x44,0x44,0x44,
0x38,0x00,0x00,0x00,0x00,0x7c,0x44,0x04,0x08,0x08,0x08,0x10,0x10,0x00,0x00,0x00,
0x00,0x38,0x44,0x44,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x38,0x44,0x44,
0x44,0x3c,0x04,0x08,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x30,
0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x18,0x30,0x20,0x00,0x00,
0x00,0x00,0x0c,0x10,0x60,0x80,0x60,0x10,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x7c,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x20,0x18,0x04,0x18,0x20,
0xc0,0x00,0x00,0x00,0x00,0x00,0x18,0x24,0x04,0x08,0x10,0x00,0x30,0x00,0x00,0x00,
0x38,0x44,0x44,0x4c,0x54,0x54,0x4c,0x40,0x44,0x38,0x00,0x00,0x00,0x30,0x10,0x28,
0x28,0x28,0x7c,0x44,0xec,0x00,0x00,0x00,0x00,0xf8,0x44,0x44,0x78,0x44,0x44,0x44,
0xf8,0x00,0x00,0x00,0x00,0x3c,0x44,0x40,0x40,0x40,0x40,0x44,0x38,0x00,0x00,0x00,
0x00,0xf0,0x48,0x44,0x44,0x44,0x44,0x48,0xf0,0x00,0x00,0x00,0x00,0xfc,0x44,0x50,
0x70,0x50,0x40,0x44,0xfc,0x00,0x00,0x00,0x00,0x7c,0x20,0x28,0x38,0x28,0x20,0x20,
0x70,0x00,0x00,0x00,0x00,0x3c,0x44,0x40,0x40,0x4c,0x44,0x44,0x38,0x00,0x00,0x00,
0x00,0xec,0x44,0x44,0x7c,0x44,0x44,0x44,0xec,0x00,0x00,0x00,0x00,0x7c,0x10,0x10,
0x10,0x10,0x10,0x10,0x7c,0x00,0x00,0x00,0x00,0x3c,0x08,0x08,0x08,0x48,0x48,0x48,
0x30,0x00,0x00,0x00,0x00,0xec,0x44,0x48,0x50,0x70,0x48,0x44,0xe4,0x00,0x00,0x00,
0x00,0x70,0x20,0x20,0x20,0x20,0x24,0x24,0x7c,0x00,0x00,0x00,0x00,0xec,0x6c,0x6c,
0x54,0x54,0x44,0x44,0xec,0x00,0x00,0x00,0x00,0xec,0x64,0x64,0x54,0x54,0x54,0x4c,
0xec,0x00,0x00,0x00,0x00,0x38,0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,
0x00,0x78,0x24,0x24,0x24,0x38,0x20,0x20,0x70,0x00,0x00,0x00,0x00,0x38,0x44,0x44,
0x44,0x44,0x44,0x44,0x38,0x1c,0x00,0x00,0x00,0xf8,0x44,0x44,0x44,0x78,0x48,0x44,
0xe0,0x00,0x00,0x00,0x00,0x34,0x4c,0x40,0x38,0x04,0x04,0x64,0x58,0x00,0x00,0x00,
0x00,0xfc,0x90,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0xec,0x44,0x44,
0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0xec,0x44,0x44,0x28,0x28,0x28,0x10,
0x10,0x00,0x00,0x00,0x00,0xec,0x44,0x44,0x54,0x54,0x54,0x54,0x28,0x00,0x00,0x00,
0x00,0xc4,0x44,0x28,0x10,0x10,0x28,0x44,0xc4,0x00,0x00,0x00,0x00,0xec,0x44,0x28,
0x28,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x7c,0x44,0x08,0x10,0x10,0x20,0x44,
0x7c,0x00,0x00,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x38,0x00,
0x00,0x40,0x20,0x20,0x20,0x10,0x10,0x08,0x08,0x08,0x00,0x00,0x00,0x38,0x08,0x08,
0x08,0x08,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x10,0x10,0x28,0x44,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,
0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,
0x44,0x3c,0x44,0x44,0x3c,0x00,0x00,0x00,0x00,0xc0,0x40,0x58,0x64,0x44,0x44,0x44,
0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x44,0x40,0x40,0x44,0x38,0x00,0x00,0x00,
0x00,0x0c,0x04,0x34,0x4c,0x44,0x44,0x44,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x38,
0x44,0x7c,0x40,0x40,0x3c,0x00,0x00,0x00,0x00,0x1c,0x20,0x7c,0x20,0x20,0x20,0x20,
0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x34,0x4c,0x44,0x44,0x44,0x3c,0x04,0x38,0x00,
0x00,0xc0,0x40,0x58,0x64,0x44,0x44,0x44,0xec,0x00,0x00,0x00,0x00,0x10,0x00,0x70,
0x10,0x10,0x10,0x10,0x7c,0x00,0x00,0x00,0x00,0x10,0x00,0x78,0x08,0x08,0x08,0x08,
0x08,0x08,0x70,0x00,0x00,0xc0,0x40,0x5c,0x48,0x70,0x50,0x48,0xdc,0x00,0x00,0x00,
0x00,0x30,0x10,0x10,0x10,0x10,0x10,0x10,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0xe8,
0x54,0x54,0x54,0x54,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0xd8,0x64,0x44,0x44,0x44,
0xec,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0xd8,0x64,0x44,0x44,0x44,0x78,0x40,0xe0,0x00,0x00,0x00,0x00,0x34,
0x4c,0x44,0x44,0x44,0x3c,0x04,0x0c,0x00,0x00,0x00,0x00,0x6c,0x30,0x20,0x20,0x20,
0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x44,0x38,0x04,0x44,0x78,0x00,0x00,0x00,
0x00,0x00,0x20,0x7c,0x20,0x20,0x20,0x20,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0xcc,
0x44,0x44,0x44,0x4c,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0xec,0x44,0x44,0x28,0x28,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0xec,0x44,0x54,0x54,0x54,0x28,0x00,0x00,0x00,
0x00,0x00,0x00,0xcc,0x48,0x30,0x30,0x48,0xcc,0x00,0x00,0x00,0x00,0x00,0x00,0xec,
0x44,0x24,0x28,0x18,0x10,0x10,0x78,0x00,0x00,0x00,0x00,0x7c,0x48,0x10,0x20,0x44,
0x7c,0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x10,0x10,0x20,0x10,0x10,0x10,0x08,0x00,
0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x20,0x10,0x10,
0x10,0x10,0x08,0x10,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x58,0x00,
0x00,0x00,0x00,0x00};
        #endregion

        public Texture2D TexWhite
        {
            get;
            private set;
        }
        public Texture2D TexLogo
        {
            get;
            private set;
        }
        public PackedTextureGroup PackedTextureGroup
        {
            get; private set;
        }
        #region 常用PackedBlock
        public PackedTextureElement BlockWhite
        {
            get
            {
                PackedTextureGroup.GetElementByName("white", out var value);
                return value;
            }
        }
        public PackedTextureElement BlockLogo
        {
            get
            {
                PackedTextureGroup.GetElementByName("logo", out var value);
                return value;
            }
        }
        public PackedTextureElement BlockCorner
        {
            get
            {
                PackedTextureGroup.GetElementByName("corner", out var value);
                return value;
            }
        }
        public PackedTextureElement BlockArrow
        {
            get
            {
                PackedTextureGroup.GetElementByName("arrow", out var value);
                return value;
            }
        }
        public PackedTextureElement BlockRound
        {
            get
            {
                PackedTextureGroup.GetElementByName("round", out var value);
                return value;
            }
        }
        public PackedTextureElement BlockBorder
        {
            get
            {
                PackedTextureGroup.GetElementByName("border", out var value);
                return value;
            }
        }
        public PackedTextureSpriteScale9 BlockBorderScale9
        {
            get
            {
                return new PackedTextureSpriteScale9(this.PackedTextureGroup, BlockBorder, Border.Two);
            }
        }
        public PackedTextureElement BlockBorder2
        {
            get
            {
                PackedTextureGroup.GetElementByName("border2", out var value);
                return value;
            }
        }
        public PackedTextureElement BlockBorderRound
        {
            get
            {
                PackedTextureGroup.GetElementByName("borderr", out var value);
                return value;
            }
        }
        #endregion

        public FontAscII12 AscII12
        {
            get; private set;
        }
        public void Init(ResourcePackage package,byte rgbapackcount=4, byte alphapackcount =4)
        {
            Package = package;
            DefShader.InitInnerShader(package);


            //初始化PackedTextureGroup 的一些常用标志
            PackedTextureGroup = new PackedTextureGroup(package, 2048, 2048, rgbapackcount, alphapackcount);

            var logoimg = TTEngine.API.loader.LoadImage(CommonResource.logo_png_bytes_cs);

            var spdata = new SpriteData(logoimg.Width, logoimg.Height, ImageFormat.RGBA, 0, 0);
            var logo = TTEngine.API.loader.LoadImage(CommonResource.logo_png_bytes_cs);
            spdata.SetData(logo.GetData());
          


            //初始化默认Texture
            DefSprite.InitInnerResource(PackedTextureGroup);


            var elem = PackedTextureGroup.AddSpriteInfo(spdata, SpriteEffect.RGBA, Border.Zero);
            PackedTextureGroup.AddElement("logo", ref elem);

            byte[] data = new byte[8 * 8 * 4];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = 255;
            }

            TexWhite = new TTEngine.Graphics.Texture2D(package, 8, 8, TextureType.RGBA_32, data);

            TexLogo = new TTEngine.Graphics.Texture2D(package, (uint)logoimg.Width, (uint)logoimg.Height, TextureType.RGBA_32, logoimg.GetData());

            AscII12 = new FontAscII12(package, CommonResource.ASCII12_bin_bytes_cs, PackedTextureGroup);

            PackedTextureGroup.ApplyTextureData();
        }

    }
}
